renderAmpCurves and renderMeltCurves

Konstantin A. Blagodatskikh

Introduction

renderAmpCurves and renderMeltCurves function represent amplification and melting data from real-time PCR experiments as curves based on plotly package. Main advantage of using this functions instead of regular plot renders is that it glued with RDML package. Minimal usage recures only GetFData(long.table = TRUE) function output. Also it have interactive feature - fast curves hiding without total plot redraw.

library(shinyMolBio)
library(tidyverse)
library(RDML)
library(chipPCR)
# load RDML file
rdml <- RDML$new(system.file("/extdata/stepone_std.rdml", package = "RDML"))
renderAmpCurves(inputId = "firstLook", # Shiny input ID
              label = "Example", # optional plot label 
              ampCurves = rdml$GetFData(long.table = TRUE), # Amplification curves
              interactive = FALSE
) 

Curves customization

Color

Curve color can be directly provided by adding column color to ampCurves table or by choosing column that defines color with colorBy param.

renderAmpCurves(inputId = "color1",
              ampCurves = rdml$GetFData(long.table = TRUE),
              colorBy = "sample", # sample name will define color
              interactive = FALSE
) 
renderAmpCurves(inputId = "color2",
              ampCurves = rdml$GetFData(long.table = TRUE) %>% 
                mutate(color = "red"), # All curves will be red
              interactive = FALSE
)

Linetype

Curve linetype can be setted by choosing column that defines linetype with linetypeBy param.

renderAmpCurves(inputId = "linetype",
              ampCurves = rdml$GetFData(long.table = TRUE),
              linetypeBy = "sample.type", # sample.type will define color
              interactive = FALSE
) 

Show Markers

You can show Cq or Tm values on curves as markers setting showCq = TRUE or showTm = TRUE. Then input table have to contain cq or tm column.

renderAmpCurves(inputId = "cq", 
              ampCurves = rdml$GetFData(
                rdml$AsTable(cq = data$cq), # Get Cq values from file
                long.table = TRUE), 
              showCq = TRUE, # Add Cq markers to curves
              colorBy = "sample",
              interactive = FALSE
) 

Show Cq Threshold Line

Threshold lines can be shown by choosing column that splits different threshold values with thBy param. Then input table have to contain quantFluor column.

# Create function for curves preprocessing
dataType$set("public", "Process",
             function(thValue) {
               # Subtract background
               private$.adp$fpoints$fluor <- 
                 CPP(self$adp$fpoints$cyc,
                     self$adp$fpoints$fluor,
                     bg.range = c(10,20))$y.norm
               # Calc Cq by threshold method
               self$cq <- th.cyc(self$adp$fpoints$cyc, self$adp$fpoints$fluor, r = thValue)[1, 1]
               # Write threshold value
               self$quantFluor <- thValue
             },
             overwrite = TRUE)

rdml <- RDML$new(system.file("/extdata/lc96_bACTXY.rdml", package = "RDML"))

Loading experiment: ca1eb225-ecea-4793-9804-87bfbb45f81d run: 65aeb1ec-b377-4ef6-b03f-92898d47488b

# Manual threshold values for different targets
thValues <- c("bACT" = 0.03, "X" = 0.05, "Y" = 0.04, "IPC" = 0.01)

# Preprocess every curve
for (react in rdml$experiment[[1]]$run[[1]]$react) {
  for (fdata in react$data) {
    fdata$Process(thValues[fdata$tar$id])
  }
}

renderAmpCurves("th", "th", 
                rdml$GetFData(
                  # Add threshold values to table
                  rdml$AsTable(quantFluor = data$quantFluor),
                  long.table = TRUE), 
                colorBy = "target",
                thBy = "target") # Add threshold lines (separated by targets)

Hiding curves

Individual curves can be hidden without plot redraw. Use updateCurves function with fdata.name as hideCurves param. Run shinyMolBio::runExample("pcrPlateInput") to see this in action.